package com.atguigu.ssyx.sys.controller;

import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.sys.RegionWare;
import com.atguigu.ssyx.sys.service.RegionWareService;
import com.atguigu.ssyx.vo.sys.RegionWareQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杨林
 * @create 2023-07-12 16:52 星期三
 * description:区域管理前端控制器
 */
@CrossOrigin  //跨域
@Api(tags = "区域管理")
@RequestMapping("/admin/sys/regionWare")
@RestController
public class RegionWareController {

    @Autowired
    private RegionWareService regionWareService;

    /**
     * 获取开通区域列表
     * @param page
     * @param limit
     * @param regionWareQueryVo
     * @return
     */
    @GetMapping("/{page}/{limit}")
    @ApiOperation(value = "获取开通区域列表")
    public Result index(@PathVariable("page") Long page,
                        @PathVariable("limit") Long limit,
                        RegionWareQueryVo regionWareQueryVo){
       IPage result = regionWareService.index(page,limit,regionWareQueryVo);
        return Result.ok(result);
    }


    /**
     * 根据id获取已开通区域
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id获取已开通区域")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable("id") Long id){
        RegionWare regionWare = regionWareService.getById(id);
        return Result.ok(regionWare);
    }

    /**
     * 新增开通区域
     * @param regionWare
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增开通区域")
    public Result save(@RequestBody RegionWare regionWare){
        regionWareService.save(regionWare);
        return Result.ok();
    }

    /**
     * 修改开通区域状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/updateStatus/{id}/{status}")
    @ApiOperation(value = "修改开通区域状态")
    public Result updateStatus(@PathVariable("id") Long id,
                               @PathVariable("status") Integer status){
        regionWareService.updateStatusById(id,status);
        return Result.ok();
    }


    /**
     * 根据id删除开通区域
     * @param id
     * @return
     */
    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "根据id删除开通区域")
    public Result removeById(@PathVariable("id") Long id){
        regionWareService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据id列表批量删除开通区域
     * @param ids
     * @return
     */
    @DeleteMapping("/batchRemove")
    @ApiOperation(value = "根据id列表批量删除开通区域")
    public Result batchRemove(@RequestBody List<Long> ids){
        regionWareService.removeByIds(ids);
        return Result.ok();
    }

}
